package com.hex.ds.em.hcdp.gauss.analyze.script.performance;

import static com.hex.ds.em.hcdp.gauss.pack.service.impl.ScriptPackTaskServiceImpl.wordResult;

import com.hex.ds.em.hcdp.basic.common.IResultForReport;
import com.hex.ds.em.hcdp.gauss.analyze.script.performance.entity.CheckUpdateEntity;
import com.hex.ds.em.hcdp.gauss.common.entity.ScriptPackScanResultEntity;
import com.hex.ds.em.hcdp.gauss.common.enums.AntlrEnum;
import com.hex.hlrt.gauss.g4.basic.gen.GaussParser.Update_statementContext;
import com.hex.hlrt.gauss.g4.basic.gen.GaussParserBaseListener;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

/**
 * @Package com.hex.ds.em.hcdp.gauss.analyze.script.performance
 * @ClassName CheckUpdateListener
 * @Description 检查 update
 * @Author gj.xu
 * @Date 2024/9/14 15:52
 * @Version v2.0
 **/
@Slf4j
@Accessors(chain = true)
@Scope(value = "prototype")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Service("Gauss-CheckUpdate")
public class CheckUpdateListener extends GaussParserBaseListener implements IResultForReport {

  @Override
  public void exitUpdate_statement(Update_statementContext ctx) {
    // 更新扫描后word指标结果
    setResultForWordReport();

    CheckUpdateEntity ruleEntity = new CheckUpdateEntity();
    ctx.addHeadAnyChild(ruleEntity);
    log.info("rule-[CheckUpdate]:");
  }


  @Override
  public void setResultForWordReport() {
    ScriptPackScanResultEntity result = wordResult
        .get(AntlrEnum.UPDATE_CHECK.getValue());
    if (result == null) {
      return;
    }
    result.setScanTable("").setScanState("fail");
    wordResult.put(AntlrEnum.UPDATE_CHECK.getValue(), result);
  }
}
